import i18n from '@/i18n'

export default function useOptions () {
  const t = i18n.global.t
  // 性别选项
  const genderOptions = [
    { value: '1', text: t('inputMethod.genderOptions.male') },
    { value: '0', text: t('inputMethod.genderOptions.female') }
  ]
  // pTNM picker options
  const ptnmPickerOptions = [
    { text: t('inputMethod.ptnmOptions.1'), value: '1' },
    { text: t('inputMethod.ptnmOptions.2'), value: '2' },
    { text: t('inputMethod.ptnmOptions.3'), value: '3' }
  ]
  // baseline ctDNA level picker options
  const baselineCtDNAStatusOptions = [
    { text: t('inputMethod.yin'), value: '0' },
    { text: t('inputMethod.yang'), value: '1' }
  ]
  // 结果映射
  const LEVEL_MAP = {
    High_risk: { colorClass: 'text-red-500', text: t('record.highRisk') },
    // M: { colorClass: 'text-yellow-500', text: i18n.t('record.mediumRisk') },
    Low_risk: { colorClass: 'text-green-500', text: t('record.lowRisk') }
  }
  /**
   * 通过value获取选项text
   * @param {Array} options 选项数组
   * @param {String} value 选项值
   * @param {String} defaultText 默认值
   * @returns {String} 选项text
   */
  const getOptText = (options, value, defaultText = '') => {
    const opt = options.find(item => item.value === value)
    return opt ? opt.text : defaultText
  }
  /**
   * 根据结果获取风险等级
   * @param result {String} 结果
   * @returns {string} 风险等级html
   */
  const getRiskLevel = (result) => {
    const item = LEVEL_MAP[result]
    if (!item) return setResultHtml('-', '')
    return setResultHtml(item.text, item.colorClass)
  }
  const setResultHtml = (text, colorClass) => {
    return `<span class="${colorClass}">${text}</span>`
  }
  return {
    genderOptions,
    ptnmPickerOptions,
    baselineCtDNAStatusOptions,
    LEVEL_MAP,
    getOptText,
    getRiskLevel
  }
}
